﻿using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using Neptuno.Component;
using Neptuno.Model;
using System;

namespace Neptuno.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class TerminalesService
    {
        TerminalesComponent Component = new TerminalesComponent();

        [WebInvoke(UriTemplate = "{id}", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool AgregarTerminal(string id, Terminales Terminal)
        {
            return Component.AgregarTerminal(Terminal);
        }

        [WebInvoke(UriTemplate = "{id}", Method = "DELETE", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Borrar(string id)
        {
            return Component.Borrar(int.Parse(id));
        }

        [WebGet(UriTemplate = "", ResponseFormat = WebMessageFormat.Json)]
        public List<Terminales> Listar()
        {
            List<Terminales> lista = Component.Listar(true);
            return lista;
        }

        [WebGet(UriTemplate = "ByPuerto/{idPuerto}", ResponseFormat = WebMessageFormat.Json)]
        public List<Terminales> ListarByPuerto(string idPuerto)
        {
            List<Terminales> lista = Component.Listar(idPuerto);
            return lista;
        }

        [WebGet(UriTemplate = "Eliminados", ResponseFormat = WebMessageFormat.Json)]
        public List<Terminales> ListarEliminados()
        {
            List<Terminales> lista = Component.Listar(false);
            return lista;
        }

        [WebGet(UriTemplate = "Restaurar/{id}", ResponseFormat = WebMessageFormat.Json)]
        public bool Restaurar(string id)
        {
            return Component.Habilitar(int.Parse(id));
        }

        [WebGet(UriTemplate = "{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Terminales GetById(string id)
        {
            return Component.GetById(int.Parse(id));
        }

        [WebInvoke(UriTemplate = "{id}", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Actualizar(string id, Terminales Terminal)
        {
            Terminal.idTerminal = int.Parse(id);
            return Component.Actualizar(Terminal);
        }
    }
}